package com.zhku.analysis.config;
/*
 *  @author : 钱伟健 gonefuture@qq.com
 *  @version    : 2018/4/2 20:16.
 *  说明：
 */

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.data.hadoop.hbase.HbaseTemplate;

/**
 * <pre> <pre>
 */
@org.springframework.context.annotation.Configuration
public class HbaseConfig {

    @Bean
    public HbaseTemplate hbaseTemplate(@Value("${hbase.zookeeper.quorum}") String quorum,
                                       @Value("${hbase.zookeeper.port}") String port) {
        // 设置haddoop的环境变量
        System.setProperty("hadoop.home.dir", "/data/install/apache/hadoop-2.9.0/");    // 集群环境
        //System.setProperty("hadoop.home.dir", "D:\\program\\hadoop"); // 本地环境
        HbaseTemplate hbaseTemplate = new HbaseTemplate();
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", quorum);
        conf.set("hbase.zookeeper.port", port);
        hbaseTemplate.setConfiguration(conf);
        hbaseTemplate.setAutoFlush(true);
        return hbaseTemplate;
    }

}
